var requireContext = require("node-require-context");
var fs = require("fs-extra");
var path = require("path");
import { readFileSync } from "fs-extra";
import { Init } from "./init";
import { CombinatorialPaternity } from "../utils";
export class AutoBase extends Init {
  constructor() {
    super();
  }
  allJsonArr = [];
  // 获取所有的json 文件列表
  getAllJson(): any[] {
    this.allJsonArr = [];
    const context = requireContext(this.getViewsPath(), true, /\.json$/);
    context.keys().forEach((moduleId: string, index: number) => {
      let data = readFileSync(moduleId);
      let str = String(data) as never;
      this.allJsonArr.push(JSON.parse(str));
    });
    return this.allJsonArr;
  }
  createAllJson() {
    let bulidJson = new CombinatorialPaternity();
    let json_demo = bulidJson.structure(this.getAllJson())

    return JSON.stringify(json_demo, null, "\t");
  }
}
